package com.zhx.dao;

import com.zhx.domain.LoginLog;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.logging.Logger;

/**
 * @program: LoginLogDao
 * @author: zhx
 * @create: 2021-03-22 20:45
 **/
@Repository
public class LoginLogDao {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate = jdbcTemplate;
    }
    //保存登陆日志
    private final static String INSERT_LOGIN_LOG_SQL = "insert into t_login_log(user_id,ip,login_datetime,register_datetime) values(?,?,?,?)";

    /**
     * 插入日志表
     * @param loginLog
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void insertLogLog(LoginLog loginLog){
        jdbcTemplate.update(INSERT_LOGIN_LOG_SQL, new Object[]{loginLog.getUserId(), loginLog.getIp(), loginLog.getLoginDate(),loginLog.getRegisterDate()});
    }
}
